﻿@{
    ViewBag.Title = "群组管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="content-header">
    <h1>
        群组管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">群组管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <form id="search-form" class="form-inline">
                        <div class="form-group">
                            <label>名称</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="11" name="txtName" id="txtName" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>品牌</label>
                            <select id="selBrand" name="selBrand" class="form-control">
                                <option value="0">全部</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>车型</label>
                            <select id="selModel" name="selModel" class="form-control">
                                <option value="0">全部</option>
                            </select>
                        </div>
                        <div data-toggle="distpicker" class="form-group">
                            <label>所在地</label>
                            <select name="HProince" id="HProince" class="form-control"></select>
                            <select name="HCity" id="HCity" class="form-control"></select>
                        </div>
                        <div class="form-group">
                            <label>创建时间</label>
                            <input type="text" class="form-control" style="width:100px;" name="BCreateDate" id="BCreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" style="width:100px;" name="ECreateDate" id="ECreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnSearch">查找</button>
                            <button class="btn btn-primary" id="btnAdd" type="button">添加</button>
                        </div>

                        <h3 class="box-title"></h3>
                    </form>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-bordered table-hover body-table-head">
                        <thead>
                            <tr>

                                <th width="10%">
                                    名称
                                </th>
                                <th width="10%">
                                    品牌
                                </th>
                                <th width="10%">
                                    车型
                                </th>
                              
                                <th width="10%">
                                    城市
                                </th>
                                <th width="10%">
                                    男性人数
                                </th>
                                <th width="10%">
                                    女性人数
                                </th>
                                <th width="10%">
                                    LOGO
                                </th>
                                <th width="10%">
                                    创建时间
                                </th>
                                <th width="10%" class="t_c">
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
                <div class="box-footer clearfix ">
                    <ul id="pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each rows}}
        <tr>

            <td class="title">
                {{$value.CarGroupName}}
            </td>
            <td class="title">
                {{$value.BrandName}}
            </td>
            <td class="title">
                {{$value.SerialName}}
            </td>
         
           
            <td>
                {{$value.CityName}}
            </td>
            <td>
                {{$value.ManTotal}}
            </td>
            <td>
                {{$value.WoManTotal}}
            </td>
            <td class="title">
                <img src="{{$value.LogoImageUrl}}" width="100" height="100" />
            </td>
            <td>
                {{$value.CreateDate}}
            </td>

            <td class="t_c">
                <button type="button" class="btn btn-warning btn-xs" onclick="jump('{{$value.CarGroupID}}')">用户</button>
                <button type="button" class="btn btn-info btn-xs" onclick="edit('{{$value.CarGroupID}}')">修改</button>
                <button type="button" class="btn btn-warning btn-xs" onclick="content('{{$value.CarGroupID}}')">微信群</button>
                <button type="button" class="btn btn-danger btn-xs" onclick="del('{{$value.CarGroupID}}')">删除</button>
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#BCreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#ECreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });

            $("#btnSearch").click(function () {
                pageIndex = 1;
                list();
            });

            list();
            bindBrand();
            $("#selBrand").change(function () {
                var bid = $(this).val();
                if (bid > 0) {
                    bindModel(bid);
                } else {
                    $("#selModel").empty();
                    $("#selModel").append('<option value=0>全部</option>');
                }
                
            })
            $("#btnAdd").click(function () {
                var url = '@Url.Action("CarGroupEdit", "Public")';
                location.href = url;
            });



        });



        //页码
        var pageIndex = 1;
        //查询
        function list() {

            var url = '@Url.Action("GetCarGroupList", "Public")' + "?page=" + pageIndex+"&rows=10";
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'POST',
                dataType: "json",
                data: {
                    Name: $("#txtName").val(),
                    BrandID: $("#selBrand").val(),
                    ModelID: $("#selModel").val(),
                    StartDate: $("#BCreateDate").val(),
                    EndDate: $("#ECreateDate").val(),
                    CityID: $("#HCity").val()
                },
                success: function (dt) {
                    if (dt.total < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var data = dt.rows;
                    var html = template('dataItemTpl', dt);
                    document.getElementById('tbodylist').innerHTML = html;
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: dt.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            list();
                        }
                    });
                }
            });
        }

        //用户详情
        function edit(id) {
            var url = '@Url.Action("CarGroupEdit", "Public")' + "?id=" + id;
            location.href = url;
        }

        function del(id) {
            var url = '@Url.Action("DelCarGroup", "Public")'
            BMCW.DataConfirm("确认要执行此操作吗?", function () {
                BMCW.ajax({
                    url: url,
                    type: "POST",
                    data: {
                        id: id
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("操作成功", function () {
                                list();
                            });

                        } else {
                            BMCW.alert(o.message);
                        }
                    }
                });
            })
        }

        function bindBrand()
        {
            var url = '@Url.Action("GetBrandList", "Public")'
            BMCW.ajax({
                url: url,
                type: "GET",
                success: function (o) {
                    if (o.length > 0) {
                        for (var i = 0; i < o.length; i++) {
                            $("#selBrand").append('<option value=' + o[i].BrandID + '>' + o[i].BrandName + '</option>');
                        }

                    } else {
                        BMCW.alert(o.message);
                    }
                }
            });
        }

        function bindModel(bid) {
            var url = '@Url.Action("GetSerialList", "Public")?brandId=' + bid;
            $("#selModel").empty();
            $("#selModel").append('<option value=0>全部</option>');
            BMCW.ajax({
                url: url,
                type: "GET",
                success: function (o) {
                    if (o.length > 0) {
                        for (var i = 0; i < o.length; i++) {
                            $("#selModel").append('<option value=' + o[i].SerialID + '>' + o[i].SerialName + '</option>');
                        }

                    } else {
                        BMCW.alert(o.message);
                    }
                }
            });
        }

        function content(id) {
            var url = '@Url.Action("WxGroupList", "Public")' + "?cid=" + id;
            location.href = url;
        }

        function jump(id) {
            var url = '@Url.Action("Index", "User")' + "?groupid=" + id;
            location.href = url;
        }
    </script>
}



